<?php 
$model = new Administrator_Model_News_View();
$siteinfo = $model->GetSiteInfo();
$title = 'Danh sách bài viết';
$button = '<button class="add button" name="btadd" value="btadd" type="submit"></button>';
switch ($this->task) {
	case 'new':
	$title = 'Thêm bài viết';
	$button = '<button class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'edit':
	$title = 'Thay đổi thông tin bài viết';
	$button = '<button class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'list':
	$title = 'Danh sách bài viết';
	$button = '<button class="add button" name="btadd" value="btadd" type="submit"></button>';
	$button .= '<button class="edit button" name="btedit" value="btedit" type="submit"></button>';
	$button .= '<button class="delete button" name="btdelete" value="btdelete" type="submit"></button>';
	$button .= '<button class="able button" name="btable" value="btable" type="submit"></button>';
	$button .= '<button class="check button" name="btcheck" value="btcheck" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	default:
		;
	break;
}
?>
<form method="post" enctype="multipart/form-data">
<div class="nav">
	<div class="navbutton">
		<?php echo $button;?>
	</div>
</div>
<div class="sheet">
	<div class="mana-title"><?php echo $title?></div>
	<div class="intro newsedit">
		<div class="form">
		<div class="big edit">
<?php 
	if($this->task != 'list'){
		if($this->task == 'edit'){
			$form = new Administrator_Form_News_Content($this->id);
			$form->render();
			$inf0 = $model->GetContentInfo($this->id);
			echo '<div class="tabcontroll"><ul>';
			echo '<li class="tab active" title="vi"><a href="#">Nội dung</a></li>';
			if($siteinfo['status']==1)echo '<li class="tab" title="en"><a href="#">Content</a></li>';
			echo '</ul></div>';
			echo '<div class="clear"></div>';
			echo '<div class="texteditor">';
			echo '<div class="vi text">';
			echo $this->textEditor('contentvi', $model->TranslateByLang($inf0['content'], 'vi'),'99%','500px');
			echo '</div>';
			if($siteinfo['status']==1){
				echo '<div class="en text" style="display:none;">';
				echo $this->textEditor('contenten',  $model->TranslateByLang($inf0['content'], 'en'),'99%','500px');
				echo '</div>';
			}
			echo '</div>';
		}
		if($this->task == 'new'){
			$form = new Administrator_Form_News_Content('');
			$form->render();
			echo '<div class="tabcontroll"><ul>';
			echo '<li class="tab active" title="vi"><a href="#">Nội dung</a></li>';
			if($siteinfo['status']==1)echo '<li class="tab" title="en"><a href="#">Content</a></li>';
			echo '</ul></div>';
			echo '<div class="clear"></div>';
			echo '<div class="texteditor">';
			echo '<div class="vi text">';
			echo $this->textEditor('contentvi', "",'99%','500px');
			echo '</div>';
			if($siteinfo['status']==1){
				echo '<div class="en text" style="display:none;">';
				echo $this->textEditor('contenten', "",'99%','500px');
				echo '</div>';
			}
			echo '</div>';
		}?>
	</div>
<script type="text/javascript">
$('.sheet .intro .form .tabcontroll li').click(function(){ 
	$('.sheet .intro .form .tabcontroll li.active').removeClass('active');
	$(this).addClass('active');
	var show = $(this).attr('title');
	$('.sheet .intro .form .texteditor .text').hide('slow');
	$('.sheet .intro .form .texteditor .'+show).show('slow');
	return false;
});
</script>
		
		
<?php
	}
	else {
echo '<table class="list-item">';
	echo '<thead>';
		echo '<th class="stt">STT</th>';
		echo '<th class="checkbox"><input id="selectall" type="checkbox" ></th>';
		echo '<th class="">Tên bài viết</th>';
		if($siteinfo['status']==1)echo '<th class="">Content name</th>';
		echo '<th class="">Danh mục</th>';
		echo '<th class="id">Hit</th>';
		echo '<th class="">User</th>';
		echo '<th class="action">Action</th>';
		echo '<th class="id">ID</th>';
	echo '</thead>';
	echo '<tbody>';
	$i=1;
	foreach ($model->GetAllContent() as $value) {
		$class="";if($i%2==0)$class = 'focus';
		echo '<tr class="'.$class.'">';
			echo '<td class="stt">'.$i.'</td>';
			echo '<td class="checkbox"><input id="'.$value['id'].'" type="checkbox" name="'.$value['id'].'" ></td>';
			echo '<td class="">'.$model->TranslateByLang($value['name'], 'vi').'</td>';
			if($siteinfo['status']==1)echo '<td class="">'.$model->TranslateByLang($value['name'], 'en').'</td>';
			$secinfo = $model->GetCatalogueInfo($value['parent']);			
			$catname = $model->TranslateByLang($secinfo['name'], 'vi');
			if($siteinfo['status']==1) $catname = $model->TranslateByLang($secinfo['name'], 'vi').' - '.$model->TranslateByLang($secinfo['name'], 'en');
			echo '<td class="">'.$catname.'</td>';
			echo '<td class="id">'.$value['hit'].'</td>';
			$uinfo = $model->GetUserInfo($value['user']);
			echo '<td class="">'.$uinfo['name'].'</td>';
			echo '<td class="action"><a href="'.BASE_URL.'/administrator/news/content?task=edit&id='.$value['id'].'"><img src="'.$this->dirImg.'/edit.png"></a><a href="#" onclick="DeleteSection()"><img src="'.$this->dirImg.'/delete.png"></a></td>';
			echo '<td class="id">'.$value['id'].'</td>';
			echo '</tr>';
		$i++;
	}
	echo '</tbody>';
	echo '<tfoot>';
	echo '</tfoot>';
echo '</table>';
}
?>		
		</div>
	</div>
</div>
</form>